package tagdb.algorithm.match;

/**
 * <b>PeptideSpectrumMatch</b>
 * <p>
 * This class holds information about a matched/identified spectrum.
 * It contains spectrumId, number of matched peaks, intensity score and mass error sum.
 * </p>
 *
 * @author T.Muth
 */
public class PeptideSpectrumMatch {

    /**
     * The spectrum title.
     */
    private String spectrumTitle;

    /**
     * The ion charge.
     */
    private int charge;

    /**
     * The number of matched peaks.
     */
    private int numMatchedPeaks;

    /**
     * The intensity score.
     */
    private double intensityScore;

    /**
     * The relative matched ion count.
     */
    private double relMatchedIonCount;

    /**
     * The number of spectrum peaks.
     */
    private int numSpectrumPeaks;

    /**
     * The matched tag rank.
     */
    private int tagRank;

    /**
     * Flag if the hit is decoy or not.
     */
    private boolean decoy;

    private String description;

    /**
     * Constructs a peptide spectrum match.
     *
     * @param charge         The ion charge.
     * @param nMatchedPeaks  The number of matches peaks.
     * @param intensityScore The intensity score.
     * @param relMatchedIonCount   The relative matched ion count.
     */
    public PeptideSpectrumMatch(int charge, int nMatchedPeaks, int nSpectrumPeaks, double intensityScore, double relMatchedIonCount, boolean decoy) {
        this.charge = charge;
        this.numMatchedPeaks = nMatchedPeaks;
        this.numSpectrumPeaks = nSpectrumPeaks;
        this.intensityScore = intensityScore;
        this.relMatchedIonCount = relMatchedIonCount;
        this.decoy = decoy;
    }

    /**
     * Returns spectrum title.
     *
     * @return The spectrum title.
     */
    public String getSpectrumTitle() {
        return spectrumTitle;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    /**
     * Sets spectrum title.
     *
     * @param spectrumTitle The spectrum title.
     */
    public void setSpectrumTitle(String spectrumTitle) {
        this.spectrumTitle = spectrumTitle;
    }

    /**
     * Returns the charge.
     *
     * @return The PSM charge.
     */
    public int getCharge() {
        return charge;
    }

    /**
     * Returns the number of matched peaks.
     *
     * @return the nMatchedPeaks
     */
    public int getMatchedPeaks() {
        return numMatchedPeaks;
    }

    /**
     * Returns the score.
     *
     * @return the intensityScore
     */
    public double getIntensityScore() {
        return intensityScore;
    }

    public double getMatchedIonsRatio() {
        if(numMatchedPeaks > 0 && numSpectrumPeaks > 0) {
            double ratio = (numMatchedPeaks * 1.0  / numSpectrumPeaks * 1.0) * 100.0;
            return tagdb.util.Formatter.roundDouble(ratio, 2);
        } else {
            return 0.0;
        }

    }

    /**
     * The relative matched ion count.
     *
     * @return Relative matched ion count.
     */
    public double getRMIC() {
        return relMatchedIonCount;
    }

    /**
     * The number of spectrum peaks.
     *
     * @return Number of spectrum peaks
     */
    public int getNumSpectrumPeaks() {
        return numSpectrumPeaks;
    }

    /**
     * Flag for PSM being decoy or not.
     * @return decoy flag
     */
    public boolean isDecoy() {
        return decoy;
    }
}
